﻿using System;

namespace StartReading.Security.Validation
{
    public class PasswordValidation : IValidation<String>
    {
        private const int MinimumPasswordLength = 6;

        private PasswordValidation()
        {
            this.EmptyStringValidator = EmptyStringValidation.Instance;
            this.MinimumLengthValidator = MinimumStringLengthValidation.Instance;
        }

        private static class PasswordValidationHolder
        {
            static PasswordValidationHolder()
            {
            }

            internal static readonly PasswordValidation PasswordValidation = new PasswordValidation();
        }

        public static PasswordValidation Instance
        {
            get { return PasswordValidationHolder.PasswordValidation; }
        }

        private IValidation<String, String> EmptyStringValidator { get; set; }
        private IValidation<String, int, String> MinimumLengthValidator { get; set; }

        /// <summary>
        ///     Validates password. 
        ///     If password is not valid, ArgumentException occured.
        /// </summary>
        /// <param name="password">Password to be validated</param>
        /// <exception cref="System.ArgumentException"></exception>
        public void IsValid( string password )
        {
            this.EmptyStringValidator.IsValid( password, "Password" );
            this.MinimumLengthValidator.IsValid( password, MinimumPasswordLength, "Password" );
        }
    }
}
